package com.example.design.bilibili.singleton;

/**
 * 双重检查--推荐使用
 */
public class SingletonTest6 {

    public static void main(String[] args) {

        for(int i = 0;i<1000000;i++){
            new Thread(()->{
                Singleton6 s = Singleton6.getInstance();
                if(s == null){
                    System.out.println(s);

                }

            }).start();
        }
    }
}

class Singleton6{

    private  static Singleton6 instance = null;

    private Singleton6() {

    }

    public static Singleton6 getInstance(){
        if(instance == null ){
            synchronized (Singleton6.class){
                if(instance == null){
                    instance = new Singleton6();
                }
            }
        }

        return instance;
    }
}
